import Cookies from 'js-cookie'

const TOKEN_KEY = 'access_token'
const REFRESH_TOKEN_KEY = 'refresh_token'

/**
 * 获取 Token
 */
export function getToken(): string | undefined {
  return Cookies.get(TOKEN_KEY)
}

/**
 * 设置 Token
 */
export function setToken(token: string): void {
  Cookies.set(TOKEN_KEY, token, { expires: 7 }) // 7天过期
}

/**
 * 移除 Token
 */
export function removeToken(): void {
  Cookies.remove(TOKEN_KEY)
}

/**
 * 获取刷新 Token
 */
export function getRefreshToken(): string | undefined {
  return Cookies.get(REFRESH_TOKEN_KEY)
}

/**
 * 设置刷新 Token
 */
export function setRefreshToken(token: string): void {
  Cookies.set(REFRESH_TOKEN_KEY, token, { expires: 7 })
}

/**
 * 移除刷新 Token
 */
export function removeRefreshToken(): void {
  Cookies.remove(REFRESH_TOKEN_KEY)
}

/**
 * 清除所有认证信息
 */
export function clearAuth(): void {
  removeToken()
  removeRefreshToken()
}

